package code.D1216;

/**
 * author : yeswater
 * date : 2023/12/16
 */

public class T206 {
    public ListNode reverseList(ListNode head) {
        ListNode pre = new ListNode();
        ListNode tmp = new ListNode();
        ListNode cur = head;
        while (cur != null) {
            tmp = cur.next;
            cur.next = pre.next;
            pre.next = cur;
            cur = tmp;
        }
        return pre.next;
    }
    
    private static class ListNode {
        int val;
        ListNode next;
        
        ListNode() {
        }
        
        ListNode(int val) {
            this.val = val;
        }
        
        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
